﻿using System;
using System.Windows.Forms;
using YArchitech.LIB;

namespace YArchitech.Temp
{
	internal static class DataGridViewCellExtern
	{
		public static void SetValue(this DataGridViewCell cell, int value)
		{
			cell.ValueType = typeof(int);
			cell.Value = value;
		}

		public static void SetValue(this DataGridViewCell cell, double value, int precision = 3)
		{
			double num = Convert.ToDouble(StringTools.DoubleToString(value, precision));
			cell.ValueType = typeof(double);
			cell.Value = num;
		}

		public static void SetValue(this DataGridViewCell cell, string newValue)
		{
			cell.Tag = newValue;
			cell.Value = newValue;
			cell.ValueType = typeof(string);
		}

		public static int GetIntValue(this DataGridViewCell cell)
		{
			if (cell.ValueType != typeof(int))
			{
				return 0;
			}
			return Convert.ToInt32(cell.Value);
		}

		public static double GetDoubleValue(this DataGridViewCell cell)
		{
			if (cell.ValueType != typeof(double))
			{
				return 0.0;
			}
			return Convert.ToDouble(cell.Value);
		}
	}
}
